<template>
	<radio-group @change="radioChange" style="display: flex;">
		<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value" style="display: flex;margin-right: 10rpx;">
			<view>
				<radio color="#2D9FFB" :value="item.value" :checked="index === current" />
			</view>
			<view>{{item.name}}</view>
		</label>
	</radio-group>
</template>

<script>
	export default {
		props: {
			value: {
				type: [String, Number],
				default: null
			},
			items: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				current: -1
			}
		},
		watch: {
			value(newVal) {
				this.current = this.items.findIndex(x => x.value === newVal)
			}
		},
		methods: {
			radioChange(e) {		
				this.current = this.items.findIndex(x => x.value === e.target.value)		
				this.$emit('input', parseInt(e.target.value))
			}
		}
	}
</script>

<style>

</style>
